package com.szamc.tableroundapi.utils;

import java.lang.reflect.Field;
import java.util.LinkedHashMap;

public class ObjectToLinkedHashMap {
    public static <T> LinkedHashMap<String, Object> toLinkedHashMap(T object) {
        LinkedHashMap<String, Object> map = new LinkedHashMap<>();
        Class<?> clazz = object.getClass();

        // 获取对象的所有字段，包括私有字段
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            try {
                field.setAccessible(true); // 确保私有字段也可以访问
                map.put(field.getName(), field.get(object));
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return map;
    }
}
